package com.ophiux.member.controller;

import com.ophiux.member.service.IMemberCardCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ophiux.common.core.base.Result;
import com.ophiux.member.model.dto.MemberCardCollectDTO;
import com.ophiux.member.model.vo.MemberCardCollectAddVo;
import com.ophiux.member.model.vo.MemberCardCollectQueryVo;
import com.ophiux.member.model.vo.MemberCardCollectUpdateVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/member/collect")
@Api(tags = "收藏名片")
public class MemberCardCollectController {
	@Autowired
    IMemberCardCollectService memberCardCollectService;

	@ApiOperation("1.收藏名片记录")
    @GetMapping
    public Result<IPage<MemberCardCollectDTO>> list(@RequestParam(required = false, defaultValue = "1") Integer current,
											 @RequestParam(required = false, defaultValue = "30") Integer size, MemberCardCollectQueryVo queryDTO) {
		IPage<MemberCardCollectDTO> page = memberCardCollectService.getPage(new Page<>(current, size), queryDTO);
        return Result.success(page);
    }

	@ApiOperation("2.新增")
	@PostMapping("/add")
	public Result add(@RequestBody MemberCardCollectAddVo vo) {
		return memberCardCollectService.insert(vo);
	}

	@ApiOperation("3.关注")
	@GetMapping("/follow/{memberId}/{collectMemberId}")
	public Result follow(@PathVariable @ApiParam("登录人id") Integer memberId, @PathVariable @ApiParam("关注的人id") Integer collectMemberId) {
		MemberCardCollectAddVo vo = new MemberCardCollectAddVo();
		vo.setMemberCardId(collectMemberId);
		vo.setMemberId(memberId);
		return memberCardCollectService.insert(vo);
	}

	@ApiOperation("4.修改")
	@PutMapping("/update")
	public Result update(@RequestBody MemberCardCollectUpdateVo vo) {
		return memberCardCollectService.update(vo);
	}

	@ApiOperation("5.删除")
	@DeleteMapping("/delete")
	public Result update(@RequestBody @ApiParam("收藏名片id,多个逗号隔开") String ids) {
		return memberCardCollectService.delete(ids);
	}

	@ApiOperation("6.收藏我的数量")
	@GetMapping("/getCollectMyCount")
	public Result getCollectMyCount(Integer memberId) {
		return memberCardCollectService.getCollectMyCount(memberId);
	}

	@ApiOperation("7.自己收藏的数量")
	@GetMapping("/getMyCollectCount")
	public Result getMyCollectCount(Integer memberId) {
		return memberCardCollectService.getMyCollectCount(memberId);
	}

}
